package com.sghd.candy.module.config.service;

import com.sghd.candy.module.bag.manager.PlayerBag;
import com.sghd.candy.module.bag.manager.PlayerBagManager;
import com.sghd.candy.module.bag.service.PlayerBagService;
import com.sghd.candy.module.element.manager.PlayerElement;
import com.sghd.candy.module.element.manager.PlayerElementManager;
import com.sghd.candy.module.skill.manager.PlayerSkill;
import com.sghd.candy.module.skill.manager.PlayerSkillManager;
import com.sghd.common.console.ConsoleBean;
import com.sghd.common.console.ConsoleCommand;
import com.sghd.common.ramcache.IEntity;
import com.sghd.common.ramcache.ServiceManager;
import com.sghd.common.ramcache.aop.AutoLocked;
import com.sghd.common.ramcache.service.EntityCacheService;
import com.sghd.pojo.candy.bag.enums.PropType;
import com.sghd.pojo.fight.game.ChessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author Allen
 * @date 2018/12/27
 */
@ConsoleBean
@Service
public class ConfigService {
    @Autowired
    private ServiceManager serviceManager;

    @ConsoleCommand(name = "reload", description = "重新加载")
    public void reload(String tableName) {
        Map<Class<? extends IEntity>, EntityCacheService> entityCacheServiceMap = serviceManager.getEntityServices();
        entityCacheServiceMap.forEach((aClass, entityCacheService) -> {
            if (tableName.equals("*config")) {
                if (aClass.getSimpleName().toLowerCase().endsWith("config")) {
                    entityCacheService.initCaches();
                }
            } else {
                if (aClass.getSimpleName().toLowerCase().equals(tableName)) {
                    entityCacheService.initCaches();
                }
            }
        });
    }

    @Autowired
    private PlayerBagManager playerBagManager;
    @Autowired
    private PlayerSkillManager playerSkillManager;
    @Autowired
    private PlayerElementManager playerElementManager;

    public void testInit(long playerId) {
        PlayerBag playerBag = playerBagManager.getPlayerBag(playerId);
        playerBagManager.change(playerBag, PropType.MONEY, 1000000);
        playerBagManager.change(playerBag, PropType.DIAMOND, 1000000);
        PlayerSkill playerSkill = playerSkillManager.getPlayerSkill(playerId);
        Set<Integer> newSkill = new HashSet<>();
        newSkill.add(1001);
        newSkill.add(1002);
        newSkill.add(1003);
        newSkill.add(1004);
        newSkill.add(1005);
        newSkill.add(1006);
        playerSkillManager.addPlayerSkill(playerSkill, newSkill);
        playerSkillManager.change(playerSkill, 1000);

        PlayerElement playerElement = playerElementManager.getPlayerElement(playerId);
        playerElementManager.change(playerElement,1000);
    }

    @ConsoleCommand(name = "tst1", description = "添加全部技能")
    public void tst1(long playerId) {
        PlayerSkill playerSkill = playerSkillManager.getPlayerSkill(playerId);
        Set<Integer> set = new HashSet<>(playerSkill.getSkillLevel().keySet());
        set.add(1000);
        set.add(1001);
        set.add(1002);
        set.add(1003);
        set.add(1004);
        set.add(1005);
        set.add(1006);
        set.add(1007);
        set.add(1008);
        set.add(1009);
        set.add(10010);
        set.add(10011);
        set.add(10012);
        set.add(10013);
        set.add(10014);
        set.add(10015);
        set.add(10016);
        set.add(10017);
        set.add(10018);
        set.add(10019);
        set.add(10020);
        set.add(10021);
        set.add(10022);
        set.add(10023);
        set.add(10024);
        set.add(10025);
        set.add(10026);
        set.add(10028);
        set.add(10029);
        set.add(10030);
        set.add(10031);
        set.add(10032);
        set.add(10033);
        set.add(10034);
        set.add(10035);
        set.add(10036);
        set.add(10037);
        set.add(10038);
        set.add(10039);
        playerSkillManager.addPlayerSkill(playerSkill, set);
    }
}
